//
//  ViewController.m
//  sinaTextDemo
//
//  Created by zc on 2414-2-24.
//  Copyright (c) 2014年 zc. All rights reserved.
//

#import "ViewController.h"

@interface ViewController ()<UITableViewDelegate,UITableViewDataSource>
@property (weak, nonatomic) IBOutlet UITableView *tableView;

@property (strong,nonatomic)CustomCell *Cell;

@property (strong,nonatomic)NSArray *resultArray;

@end

@implementation ViewController

- (void)viewDidLoad
{
    [super viewDidLoad];
	// Do any additional setup after loading the view, typically from a nib.
    
    NSString *resPath = [[NSBundle mainBundle]pathForResource:@"SinaData" ofType:@"txt"];
//    NSString * contentString = [NSString stringWithContentsOfFile:resPath encoding:NSUTF8StringEncoding error:nil];
    
    NSData *data = [NSData dataWithContentsOfFile:resPath];
    
    _resultArray = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableLeaves error:nil];
    NSLog(@"%@",_resultArray);
    
    
    self.Cell = [[CustomCell alloc]init];
    
    
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}



-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    NSDictionary *dic = [_resultArray objectAtIndex:indexPath.row];
    
    [self.Cell setContent:dic];
    CGFloat height = [_Cell height:dic];
    NSLog(@"Cell height is %2f",height);
    return  height;
}

-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    
    
    return 1;
}


-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    
    return [_resultArray count];
    
    
}


-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    
    static NSString * iden = @"sinaCell";
    
    CustomCell *cell = [tableView dequeueReusableCellWithIdentifier:iden];
    if (cell == nil) {
        cell = [[CustomCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:iden];
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        
    }
    
    NSDictionary *dic = [_resultArray objectAtIndex:indexPath.row];
    
    [cell setContent:dic];
        

    return cell;
    
    
}

@end
